<?php

class Error {
    private $_errors;
    private static $_instance = null;
    
    private function __construct() {
        $this->_errors = array();
    }
    
    public static function instance() {
        if(is_null(self::$_instance)) {
            self::$_instance = new Error();
        }
        return self::$_instance;
    }
    
    public function add($error) {
        $this->_errors[] = $error;
    }
    
    public function get($clear=false) {
        $errors = $this->_errors;
        if($clear) {
            $this->_errors = array();
        }
        return $errors;
    }
    
    public function count() {
        return count($this->_errors);
    }
}

?>
